package offer;

/**
 * @Auther ZhanBo
 * @Date 2020/5/21
 */
public class Solution5 {

    public static void main(String[] args) {
        String s= "We are happy.";
        System.out.println(replaceSpace(s));
    }


    /**
     *
     * 输入：s = "We are happy."
     * 输出："We%20are%20happy."
     * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
     * @param s
     * @return
     */
    public static String replaceSpace(String s) {
        StringBuffer buffer = new StringBuffer();
        char[] chars = s.toCharArray();
        for (char c :chars){
            if(c==' ') {
                buffer.append("%20");
            } else {
                buffer.append(c);
            }
        }
        return buffer.toString();
    }
}
